package com.solomiao.demo.multi.thread.demo10;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MainDemo101 {
    private static final Logger LOGGER = LoggerFactory.getLogger(MainDemo101.class);

    private static final Object lock = new Object();

    public static void main(String[] args) throws InterruptedException {
        LOGGER.info("主线程开始运行");
        BlockRunnable1 blockRunnable1 = new BlockRunnable1();
        BlockRunnable2 blockRunnable2 = new BlockRunnable2();
        Thread t1 = new Thread(blockRunnable1);
        Thread t2 = new Thread(blockRunnable2);
        t1.start();
        t2.start();
        Thread.sleep(1000);
        LOGGER.info("线程2的状态：" + t2.getState().toString());
    }

    static class BlockRunnable1 implements Runnable {
        @Override
        public void run() {
            synchronized (lock) {
                LOGGER.info("BlockRunnable1");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    static class BlockRunnable2 implements Runnable {
        @Override
        public void run() {
            synchronized (lock) {
                LOGGER.info("BlockRunnable2");
            }
        }
    }

}
